package com.test.util;

import com.zyncro.api.model.IApiType;

public final class ApiUtil {

	private ApiUtil() {

	}

	public static <T extends Enum<? extends IApiType>> T asEnum(Class<T> enumClass, int actualValue) {

		Enum<? extends IApiType> value = null;

		Enum<? extends IApiType>[] values = enumClass.getEnumConstants();

		int i = 0;

		while (i < values.length && value == null) {

			IApiType enumValue = (IApiType) values[i];

			if (enumValue.getId() == actualValue) {

				value = values[i];
			} else {
				i++;
			}
		}
		@SuppressWarnings("unchecked")
		T enumValue = (T) value;

		return enumValue;
	}
}
